package com.heima.api.fallback;

import com.heima.api.ArticleClient;
import com.heima.common.exception.CustomException;
import com.heima.model.article.dto.ArticleDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

/**
 * @projectName: heima-leadnews
 * @package: com.heima.api.fallback
 * @className: ArticleClientFallback
 * @author: 躺着认真玩
 * @description: 文章防止级联失败
 * @date: 2025/5/24 12:28
 * @version: 1.0
 */
@Slf4j
public class ArticleClientFallback implements FallbackFactory<ArticleClient> {
    @Override
    public ArticleClient create(Throwable cause) {
        return new ArticleClient() {
            @Override
            public ResponseResult submitArticle(ArticleDto articleDto) {
                log.error("远程调用ArticleClient-submitArticle时发生错误");
                // 抛出异常 进行回滚
                throw new CustomException(AppHttpCodeEnum.ANERROROCCURREDWITHREMOTECALL);
            }
        };
    }
}
